<template>
	<view class="mana-box">
		<view class="top-box" style="background-color: #FFFFFF;position: fixed;z-index: 999;width: 750rpx;">
			<view class="searchBox u-m-t-30 u-m-b-26 u-flex u-row-between" style="background-color: #1DA9FF;">
				<view class="searchtext">
					<text class="stext huFamily"> 文章搜索 </text>
				</view>
				<view class="b-rr-44 u-font-24 u-weight-500 u-flex"
					style="width: 430rpx;height: 74rpx;background-color: white;margin-right: 6rpx;">
					<u--input @input="clickSear" @confirm="clickSear" v-model="listData.searchText" placeholder="输入文章名称"
						placeholderStyle="fontSize:28rpx;color:#a8a8a8;"></u--input>
					<view class="u-m-r-20" @click="clickSear">
						<u-icon name="search" color="#666666" size="24"></u-icon>
					</view>
				</view>
			</view>
			<u-tabs :list="tabList" lineBgSize="cover" :scrollable="false" @click="clickTab"></u-tabs>
		</view>
		<view class="con-list" style="padding-top: 240rpx;">
			<view class="con-item" @click="toUrl(`/pages/newsPart/index/newsDetail?newsId=${item.newsId}`)"
				v-for="(item,index) in dataList" :key="index">
				<u-image :lazyLoad="true" width="220rpx" height="160rpx" radius="10rpx" class="use-img"
					:src="item.images">
				</u-image>
				<view class="con-info" style="flex: 1;margin-left: 20rpx;display: flex; align-items: center;">
					<view class="list-content" style="display: flex;flex-direction: column;width: 330rpx;">
						<text class="con-title">{{item.title}}</text>
						<text
							class="con-time">{{timeDifference($u.timeFormat(new Date(item.publishDate),'yyyy-mm-dd hh:MM'))}}</text>
						<view v-if="!newsCompany" class="bom-box" style="margin-top: 20rpx;">
							<view class="bom-item">
								<image style="width: 35rpx;" src="https://job.ydylmold.cn/article/image/yanjing.png"
									mode="widthFix"></image>
								<text class="count-text">{{item.browseQty || 0}}</text>
							</view>
							<view class="bom-item">
								<image style="width: 35rpx;" src="https://job.ydylmold.cn/article/image/pinglun.png"
									mode="widthFix"></image>
								<text class="count-text">{{item.commentNum || 0}}</text>
							</view>
							<view class="bom-item">
								<image v-if="!item.usrThumbsStatus" style="width: 32rpx;"
									src="https://job.ydylmold.cn/article/image/dianzan.png" mode="widthFix"></image>
								<image v-else style="width: 32rpx;"
									src="https://job.ydylmold.cn/article/image/zanred.png" mode="widthFix"></image>
								<text class="count-text">{{item.usrThumbsNum || 0}}</text>
							</view>
						</view>
					</view>

					<view class="box-con1" style="display: flex;flex-direction: column;">
						<button type="warn" @click.stop="delItem(item,index)" style="font-size: 24rpx;">删除</button>
						<!-- <button type="primary" @click.stop="editItem(item,index)"
							style="font-size: 24rpx;margin-top: 30rpx;">编辑</button> -->
					</view>
				</view>
			</view>
			<my-empty tipText="数据为空" image="http://cdn.uviewui.com/uview/empty/data.png" v-if="isEmpty"></my-empty>
			<view class="u-m-t-50" v-else>
				<u-loadmore :status="status" ></u-loadmore>
			</view>
		</view>
		<view class="fix-box" @click="toUrl('/pages/newsPart/manaPage/addArticle')">
			<u-icon name="plus" color="rgb(60, 156, 255)" size="30"></u-icon>
		</view>
		<my-auth-modal></my-auth-modal>
	</view>
</template>

<script>
	import {
		getToken
	} from '@/utils/token.js'
	import {
		timeDifference
	} from '@/utils/formaterTime.js'
	import {
		mapGetters
	} from 'vuex';
	import {
		queryProtalNews2,
		deleteData,
		deleteCompanyNews,
		deletePortalNews
	} from '@/common/api/news.js'
	import {
		duplicateRemoval
	} from '@/utils/common.js'
	export default {
		data() {
			return {
				tabList: [{
						name: '已通过',
						value: 1
					},
					{
						name: '审核中',
						value: 0
					},
					{
						name: '未通过',
						value: 2
					}
				],
				listData: {
					'page.current': 1,
					searchText: "",
					contentType: 4,
					auditState: 1,
					craftsmanId: getToken('useNum')
				},
				dataList: [],
				status: 'loading',
				isEmpty: false,
				newsCompany:getToken('newsCompany'),
				filePath: 'https://www.ydylmold.cn/file/getPlayResource/'
			}
		},
		onReachBottom: function() {
			if (this.status == 'loadmore') {
				this.listData.page++
				this.getList()
			}
		},
		onPullDownRefresh(){
			this.getNewList()
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onShow: function() {
			if (this.isFresh) {
				this.getNewList()
				this.$store.commit('isFresh', false)
			}
		},
		onLoad: function() {
			this.getList()
		},
		computed: {
			...mapGetters(['isFresh']),
		},
		methods: {
			timeDifference,
			toUrl(url) {
				uni.navigateTo({
					url: url
				})
			},
			getNewList() {
				this.dataList = []
				this.listData['page.current'] = 1
				this.getList()
			},
			getList() {
				let params = {
					'page.current': this.listData.page,
					searchText: this.listData.searchText,
					state: this.listData.auditState,
					typeId: '',
					companyNo: getToken('useNum'),
				}
				if(getToken('version') == 2){
					params['companyNo'] = getToken('useNum')
				}
				queryProtalNews2(params).then(res => {
					res = res.data
					if (res.rows && res.rows.length) {
						res.total <= res.page.total ? this.status = 'nomore' : this.status = 'loadmore'
						let list = res.rows
						if(getToken('newsCompany')){
							list.map(v=>{v.images = this.filePath+'182/'+ v.imgTitle})
						}else{
							list.map(v=>{v.images = this.filePath+'108/'+ v.imgTitle})
						}
						//console.log(list,99999)
						this.dataList = duplicateRemoval(this.dataList, res.rows, 'newsId')
						this.isEmpty = false
						//console.log(res.rows,9999)
					} else {
						this.status = 'nomore'
						this.isEmpty = true
					}
				})
			},
			clickTab(e) {
				this.listData.auditState = e.value
				this.getNewList()
			},
			clickSear(e) {
				this.listData.searchText = e
				this.getNewList()
			},
			delItem(item, index) { //删除
				uni.showModal({
					title: '提示',
					content: '删除后数据不可恢复，您确定删除吗？',
					success: (e) => {
						if (e.confirm) {
							let params = {}
							let apiName = ''
							if(this.newsCompany){
								params = {
									id:item.newsId,
								}
								apiName = 'newsData.deleteCompanyNews'
							}else{
								// apiName = 'newsData.deleteData'
								apiName = 'newsData.deletePortalNews'
								
								params['id'] = item.newsId
								params['companyNo'] = getToken('useNum')
								deletePortalNews(params).then(res=>{
									res =res.data
								if(res.code){
									this.dataList.splice(index,1)
									this.$store.commit('isFresh', true)
								}
							})
							}
						}
					}
				})
			},
			editItem(item, index) { //修改
				uni.navigateTo({
					url: `/pages/newsPart/manaPage/addArticle?itemId=${item.newsId}`
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.searchBox {
		margin: 0 30rpx;
		height: 82rpx;
		border-radius: 44rpx;
		align-items: center;
	
		// padding: 0 12rpx;
		.searchtext {
			margin: 0 26rpx;
			font-size: 48rpx;
			font-weight: 400;
			color: rgba(255, 255, 255, 1);
	
			.stext {
				text-shadow: 0rpx 6rpx 10rpx 0rpx rgba(0, 0, 0, 0.25);
			}
		}
	}

	.fix-box {
		position: fixed;
		bottom: 100rpx;
		right: 30rpx;
		width: 80rpx;
		height: 80rpx;
		background-color: #FFFFFF;
		box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
		border-radius: 15rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.content {
		background-color: #F0F0F0;
	}

	.con-item {
		display: flex;
		flex-direction: row;
		width: 750rpx;
		align-items: center;
		background-color: #FFFFFF;
		padding: 15rpx 12rpx;
		border-bottom: 1rpx solid #e1e1e1;

	}

	.con-title {
		font-size: 28rpx;
		// width: 480rpx;
		max-width: 380rpx;
		min-width: 380rpx;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
	}

	.con-time {
		font-size: 24rpx;
		color: #a8a8a8;
	}

	.con-img {
		width: 220rpx;
		height: 160rpx;
		margin-right: 20rpx;
	}

	.bom-box {
		display: flex;
		align-items: center;
	}

	.bom-item {
		display: flex;
		align-items: center;
		// margin-left: 20rpx;
	}

	.iconitem {
		font-size: 30rpx;
		color: #808080;
		line-height: 40rpx;
		margin-left: 5rpx;
	}

	.count-text {
		font-size: 24rpx;
		font-family: Source Han Sans SC;
		font-weight: 500;
		color: #808080;
		margin: 0 15rpx;
	}
</style>
